package cn.HuanG.quartz.service.impl;

import cn.HuanG.quartz.domain.QuartzJobInfo;
import cn.HuanG.quartz.job.MainJob;
import cn.HuanG.quartz.service.IQuartzService;
import cn.HuanG.util.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzServiceImpl implements IQuartzService {

    @Autowired
    private SchedulerFactoryBean factoryBean;

    @Override
    public void addJob(QuartzJobInfo quartzJobInfo) {
        QuartzUtils.addJob(factoryBean.getScheduler(),quartzJobInfo.getJobName(),
                MainJob.class,quartzJobInfo.getParams(),quartzJobInfo.getCronj());
    }

    @Override
    public void removeJob(String jobName) {
        QuartzUtils.removeJob(factoryBean.getScheduler(),jobName);
    }
}
